// 发送异步ajax请求函数模块化  axios封装

// 函数返回值是Promise对象

import axios from 'axios'
import {message} from 'antd'

export default function(url,data={},type='GET'){
    return new Promise((resolve,reject) => {
        let promise
        // ajax请求
        if(type==='GET'){
            promise = axios.get(url,{params:data})
        }else{
            promise = axios.post(url,data)
        }

        promise.then(res => {
            resolve(res)
        }).catch(error => {
            message.error('请求出错'+error.message)
        })

    }) 
}
